package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarGarage;
import com.ruoyi.car.service.ICarGarageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车库Controller
 * 
 * @author ruoyi
 * @date 2022-12-02
 */
@RestController
@RequestMapping("/car/garage")
public class CarGarageController extends BaseController
{
    @Autowired
    private ICarGarageService carGarageService;

    /**
     * 查询车库列表
     */
    @PreAuthorize("@ss.hasPermi('car:garage:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarGarage carGarage)
    {
        startPage();
        List<CarGarage> list = carGarageService.selectCarGarageList(carGarage);
        return getDataTable(list);
    }

    /**
     * 导出车库列表
     */
    @PreAuthorize("@ss.hasPermi('car:garage:export')")
    @Log(title = "车库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarGarage carGarage)
    {
        List<CarGarage> list = carGarageService.selectCarGarageList(carGarage);
        ExcelUtil<CarGarage> util = new ExcelUtil<CarGarage>(CarGarage.class);
        util.exportExcel(response, list, "车库数据");
    }

    /**
     * 获取车库详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:garage:query')")
    @GetMapping(value = "/{garageId}")
    public AjaxResult getInfo(@PathVariable("garageId") Long garageId)
    {
        return success(carGarageService.selectCarGarageByGarageId(garageId));
    }

    /**
     * 新增车库
     */
    @PreAuthorize("@ss.hasPermi('car:garage:add')")
    @Log(title = "车库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarGarage carGarage)
    {
        return toAjax(carGarageService.insertCarGarage(carGarage));
    }

    /**
     * 修改车库
     */
    @PreAuthorize("@ss.hasPermi('car:garage:edit')")
    @Log(title = "车库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarGarage carGarage)
    {
        return toAjax(carGarageService.updateCarGarage(carGarage));
    }

    /**
     * 删除车库
     */
    @PreAuthorize("@ss.hasPermi('car:garage:remove')")
    @Log(title = "车库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{garageIds}")
    public AjaxResult remove(@PathVariable Long[] garageIds)
    {
        return toAjax(carGarageService.deleteCarGarageByGarageIds(garageIds));
    }
}
